<!-- 资讯管理 -->
<template>
  <div class="page-box h100 display-flex czbj">
    <p class="title-label mb10">资讯列表</p>
    <!-- sonRouter="yybureauFormationBJ" 为跳转新的页面编辑 -->
    <dxtable
    v-if="jjdfds"
      :dataJson="dataJson"
      :portUrl="portUrl"
      :formJson="formJson"
      :qx="qx"
      ref="databale"
    ></dxtable>
    <n-modal v-model:show="showModal" preset="card" class="Stock-diagnosis">
    <template #header>
    <div>查看评论</div>
    </template>
    <div>
      <n-table :single-line="false">
    <thead>
      <tr>
        <th>姓名</th>
        <th>评价内容</th>
        <th>评价时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
      <tr v-for="sd in jsdfsf">
        <td style="width:120px">{{ sd.name }}</td>
        <td>{{ sd.text }}</td>
        <td style="width:180px">{{ sd.addTime }}</td>
        <td  style="width:80px">
            <span class="red sz" @click="sanchusd(sd)">删除</span>
        </td>
      </tr>
    </tbody>
  </n-table>
    <div v-if="jsdfsf.length<=0" class="cen pt40">
        <img src="../../assets/img/noData.png" style="width: 160px;">
        <p class="z9 fz12">暂无数据！</p>
    </div>
    </div>
    <template #action>
    <div class="tr">
    <n-button @click="showModal=false"> 关闭 </n-button>
    </div>
    </template>
    </n-modal>
  </div>
</template>
<script lang="ts" setup>
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost,dialog,dxdel } from "../../util/index";
import { NButton, NImage, NTag,NSwitch } from "naive-ui";
import { h, ref, reactive } from "vue";
const databale = ref();
const showModal = ref(false)
const jsdfsf = ref([])
const xwid =ref()
const jjdfds =ref(false)
const initeer = () => {
  databale.value.initDataExpose();
};

let dataJson = [
  {
    title: "新闻标题",
    type: "input",
    value: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "name",
    width: "",
    search: true,
    istable: true,
    required: true,
  },
  {
    title: "类型",
    type: "select",
    options: [],
    value: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "leixing",
    width: "120",
    search: true,
    istable: true,
    required: false,
    render: (row) => {
       try{
        return  dataJson[1].options.filter(a=>a.value==row.leixing)[0].label
       }catch(e){
        
       }
    }
  },
  {
    title: "封面",
    type: "img",
    val: "",
    icon: "dx-img",
    span: 12,
    key: "cover",
    search: false,
    istable: true,
    required: false,
    width:120,
  }, {
    title: "设为banner",
    key:"isbanner",
    width:120,
    render: (row) => {
       return h(NSwitch,{'default-value':row.isbanner==2?true:false, "on-update:value": async(e) => {
        let jdfds = 2
        if(row.isbanner==2){
            jdfds=1
        }
            await dxpost(portUrl.value,{id:row.id,isbanner:jdfds},"put")
       }})
    }
  },{
    title: "设为首页推荐",
    key:"indexbanner",
    width:120,
    render: (row) => {
       return h(NSwitch,{'default-value':row.indexbanner==2?true:false, "on-update:value": async(e) => {
        let jdfds = 2
        if(row.indexbanner==2){
            jdfds=1
        }
            await dxpost(portUrl.value,{id:row.id,indexbanner:jdfds},"put")
       }})
    }
  },{
    title: "评论",
    key:"isbanner",
    width:120,
    render: (row) => {
      return h('span',{class:"ls sz",onClick:()=>{
        xwid.value=row.id
        showModal.value = true
      getpingjia()
      }},"点击查看评论")
    }
  },


  
  {
    title: "排序",
    width: 100,
    render: (row) => {
      row.sjk = "chuanbo"; //数据库
      row.databaseName = "zixun"; //表名
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];

const qx = {
  DeletePermissionID: "cbrczixundel", //删除
  EditPermissionIdentifier: "cbrczixunbj", // 编辑
  NewPermissionIdentifier: "cbrczixunxz", // 新建
  ViewPermissionID: "cbrczixunck", // 查看
};


let formJson = reactive([
  {
    title: "标题",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "name",
    width: "",
    search: false,
    istable: true,
    required: true,
  },
  {
    title: "类型",
    type: "select",
    options: [],
    val: [],
    span: 12,
    key: "leixing",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "封面",
    type: "img",
    val: "",
    icon: "dx-img",
    span: 12,
    key: "cover",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "详情",
    type: "fwb",
    val: "",
    icon: "dx-m-fuwenben",
    span: 24,
    key: "xq",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
]);
const czFun = {
  fun: (row) => {
    return [
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {},
        },
        "复制代码"
      ),
    ];
  },
};

const getpingjia = async()=>{
  const {data} = await dxget("cbrc/xinwenpj/xinwenpj",{xwid:xwid.value})
  console.log(data);
  jsdfsf.value = data
}


const sanchusd= async(retzx)=>{
  let statics: any = await dialog("此操作将永久删除, 是否继续?");
  
  const {data} = await dxdel("cbrc/xinwenpj/xinwenpj",{id:retzx.id})
  getpingjia()
}
let portUrl = ref('cbrc/zixun/zixun');
// 获取字典内容
const xtgxxmfl = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: 'cbrcxwrcfl' })
  dataJson[1].options = [
    ...data
  ]
  formJson[1].options = data
  dataJson[1].value = data[0].value
  jjdfds.value = true
}
xtgxxmfl()
</script>
<style scoped></style>
